// pages/yuyue/yuyue.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemId:[],
    date:[],
    selectDate:[],
    img_src:getApp().img_src,
    inputValue:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (t) {
    var data = getApp().helper.newTime()
    getApp().bus.onLoad(this)
    this.setData({
      data:data,
      selectDate:[data[0]],
      itemId:JSON.parse(t.activeId)
    })
  },
  _date(e){
    this.setData({
      'selectDate[0]':e.detail.value
    })
  },
  _time(e){
    this.setData({
      'selectDate[1]':e.detail.value
    })
  },


  clearDoctor(){
    this.setData({
      doctorId:null
    })
  },

  bindinput(e){
    this.data.inputValue = e.detail.value
  },
  mySubmit(){
    var d = this.data,
      customerId=getApp().customerId;
    if(!customerId){
      wx.showToast({title:'请授权手机号',icon:'none'})
      return
    }
    if(!d.itemId.length){
      wx.showToast({title:'请选择要预约的项目',icon:'none'})
      return
    }
    if(d.selectDate.length<2){
      wx.showToast({title:'请选择到院时间',icon:'none'})
      return
    }
    getApp().request({
      url:'https://live.sgwxmini.com/beauty/reserveUpdate/sub',
      data:{
        hosId:getApp().api.siteinfo.hosId,
        customerId:customerId,
        itemId:d.itemId.map(i=>i.id).toString(),
        doctorId:d.doctorId?d.doctorId.userId:'',
        time:d.selectDate[0],
        period:d.selectDate[1],
        remark:d.inputValue,
        deptId:d.itemId[0].dept_id,
        type:0,
      },
      loading:true,
      success(e){
        e.result == 0 ? wx.navigateTo({
          url:'/pages/yuyue/order/order?id='+e.reserveId
        }) : wx.showToast({title:e.message,icon:'none'})
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})